/**
 *
 */
package com.yangtao.prototype.system.user.web;

import com.yangtao.framework.web.struts2.BaseAction;
import com.yangtao.prototype.system.user.service.UserService;
import org.apache.commons.lang.StringUtils;

/**
 * @author 杨涛
 */
public class UserAction extends BaseAction<UserModel, UserService> {

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 查询页面初始化方法
	 *
	 * @return
	 */
	public String query() {
		// request.setAttribute("companyList", service.getCompanys(getUser()
		// .getCompanyId()));
		// list();
		return render("UserQuery");
	}

	/**
	 * 保存一个用户信息
	 *
	 * @return
	 */
	public String save() {
		String pk = model.getTargetUser().getId();
		if (StringUtils.isEmpty(pk)) {
			model = service.addUser(model);
		} else {
			model = service.updateUser(model);
		}
		return renderJsonMessage();
	}

	/**
	 * 加载单个用户信息
	 *
	 * @return
	 */
	public String load() {
		model = service.loadUser(model);
		model = service.loadAvailableResource(model);
		return render("UserDetail");
	}

	/**
	 * 删除一个用户
	 *
	 * @return json格式的消息字符串
	 */
	public String delete() {
		model = service.deleteUser(model);
		return renderJsonMessage();
	}

	/**
	 * 分页查询方法
	 *
	 * @return json格式的数据
	 */
	public String list() {
		model = service.list(model);
		return renderJson(model.getPage());

	}
}
